package drawingBoard.tool;

import drawingBoard.ImageFrame;
import java.util.Map;
import java.util.HashMap;


public class ToolFactory {   //静态工厂
	private static Map<String, Tool> toolMap = null;

	public static Tool getToolInstance(ImageFrame frame, String type) {  //静态方法
		if (toolMap == null) {
			//创建Map集合，保存各种工具
			toolMap = new HashMap();
			toolMap.put(Tool.PENCIL_TOOL, PencilTool.getInstance(frame));
			toolMap.put(Tool.BRUSH_TOOL, BrushTool.getInstance(frame));
			toolMap.put(Tool.ERASER_TOOL, EraserTool.getInstance(frame));
			toolMap.put(Tool.LINE_TOOL, LineTool.getInstance(frame));
			toolMap.put(Tool.RECT_TOOL, RectTool.getInstance(frame));
			toolMap.put(Tool.POLYGON_TOOL, PolygonTool.getInstance(frame));
			toolMap.put(Tool.ROUND_TOOL, RoundTool.getInstance(frame));
			toolMap.put(Tool.ROUNDRECT_TOOL, RoundRectTool.getInstance(frame));
			toolMap.put(Tool.ATOMIZER_TOOL, AtomizerTool.getInstance(frame));
			toolMap.put(Tool.COLORPICKED_TOOL, ColorPickedTool.getInstance(frame));
			toolMap.put(Tool.TEXT_TOOL, TextTool.getInstance(frame));
		}
		return toolMap.get(type); //根据工具类型名（接口参数）创建相应的工具
	}
}
